Audio
music
music(N, [FADE_LEN], [CHANNEL_MASK])
Play music starting from pattern N (0..63)
- N = 0-63, Play from music template N
- N = -1, stop
FADE_LEN: transition time (ms) (default: 0).
Example: Play from template 0, transition time 1 second.
music(0, 1000)
CHANNEL_MASK: Define the channels reserved for music (bit mode).
Example, only play on channels 0-2:
music(0, nil, 7) -- 1 | 2 | 4
If the command to play the sound effect specifies a channel to use, the sound effect ignores the reserved option, and if no channel is specified, the reserved channel will not be used.
sfx
sfx(N, [CHANNEL], [OFFSET], [LENGTH])
Play the sound effect N on the specified channel (CHANNEL), OFFSET is the data offset point of the sound effect, and LENGTH is the data length.
CHANNEL special value:
- CHANNEL -1: (default) automatically select an unused channel.
- CHANNEL -2: Pause all sound effects.
N special value:
- N -1: Stop the sound effect of the specified channel.
- N -2: Stop the sound effect loop of the specified channel.
sfx(3) -- play sound effect 3
sfx(3,2) -- play sound effect 3, use channel 2
sfx(3,-2) -- notify all channels of the sound effect 3
sfx(-1,2) -- stop sound effects on channel 2
sfx(-2,2) -- stop sound effects looping on channel 2
sfx(-1) -- stop all sound effects
sfx(-2) -- exit all sound loops
wave
wave(data, [from, to, audiotype])
Play pcm audio data directly, the audio needs to meet the device specification 22050hz, 16bit little format.
data has a special meaning when it is a special value:
- wave('I') -- initialization (apply for internal resources)
- wave('R') -- reset data buffer
- wave('D') -- release resources
- wave('L') -- returns remaining buffer size
- wave() -- returns remaining buffer size
audiotype indicates the audio type, the default is PCM.
- 1 : adpcm
- 2 : G711a
coloX-4
version 1
__lua__
local wavefile={
#blob :ea:22050: canon.pcm
}
local curpos=0
wave('I')
function _update()
if wave()>22050 then
curpos=curpos+1
local c=wavefile[curpos]
if c then
wave(c,nil,nil,1)
else
curpos=0
end
end
end
function _draw()
cls(dark_green)
end
micpoll [version>=7]
micpoll([flag,maxlen, audiotype])
get mic data. 22050hz, 16bit little. need open mic on sys setting.
flag :
- 1 -- clear buffer
- 2 -- get valid data length(16bit)
- 3 -- get data, maxlen to limit the max return data length(16bit)
- 4 -- get fft info, return: avg,maxidx,maxval,[ffts]. for ffts, maxlen means how many seq points will be return. 0 means no need ffts data ,1 means return fft[0] data,n(n>1) means return table include n seq data
audiotype indicates the audio type, the default is PCM.
- 1 : adpcm
- 2 : G711a
coloX-4
version 1
__lua__
wave('I')
micpoll(1)
function _update()
local d=micpoll(nil,nil,1)
if d then
wave(d,nil,nil,1)
end
end
function _draw()
cls(dark_green)
end